package com.winnie.service.impl;

import com.winnie.bean.UserEntity;
import com.winnie.mapper.UserMapper;
import com.winnie.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

@Slf4j
@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    private UserMapper userMapper;
    /**
     * 验证用户
     * @param username
     * @param password
     * @return
     */
    @Override
    public UserEntity findUser(String username, String password) {
        UserEntity user = userMapper.findUser(username, password);
        return user;
    }

    /**
     * 查询用户
     * @param username
     * @return
     */
    @Override
    public UserEntity getUser(String username) {
        return userMapper.getUser(username);
    }

    /**
     * 查找角色
     * @param username
     * @return
     */
    @Override
    public Set<String> findRole(String username) {
        return userMapper.findRole(username);
    }

    /**
     * 查找权限
     * @param username
     * @return
     */
    @Override
    public Set<String> findPermission(String username) {
        return userMapper.findPermission(username);
    }

    /**
     * 添加用户
     * @param username
     * @param password
     */
    @Override
    public void addUser(String username, String password) {
        Md5Hash md5Hash = new Md5Hash(password, username, 3);
        userMapper.insert(username, md5Hash.toString());
    }
}
